package InterviewsExposed;

public class Search {
	
	static int UNSORTED = -3;
	static int NOT_IN_ARRAY = -1;
	
	
	public static int binarySearch(int array[], int lower, int upper, int target){
		
		if (lower < upper) {
	        int mid = lower + (upper - lower) / 2;  // Compute mid point.
	        if (target < array[mid]) {
	            return binarySearch(array, lower, mid, target);
	            
	        } else if (target > array[mid]) {
	            return binarySearch(array, mid+1, upper , target);
	            
	        } else {
	            return mid;   // Found it.
	        }
	    }
	    return -(upper + 1);  // Failed to find key
	}
}